package com.ydy.shoot;

import java.util.Random;

/** 小蜜蜂: 是飞行物，也是奖励 */
public class Bee extends FlyingObject implements Award {
    private int xSpeed = 1; //x坐标走步步数
    private int ySpeed = 2; //y坐标走步步数
    private int awardType; //奖励类型


    /** 构造方法 */
    public Bee(){
        image = ShootGame.bee; //图片
        width = image.getWidth();   //宽
        height = image.getHeight(); //高
        y = -height; //y:负的蜜蜂的高
        Random rand = new Random(); //创建随机数对象
        x = rand.nextInt(ShootGame.WIDTH-this.width); //x:0到(屏幕宽-蜜蜂宽)之内的随机数
        awardType = rand.nextInt(2); //奖励类型为0到1之间的随机数
//		x=100;
//		y=200;
    }

    /** 重写getType() */
    public int getType(){
        return awardType;
    }

    /** 重写step() */
    public void step(){
        x+=xSpeed; //x加(向左或向右)
        y+=ySpeed; //y加(向下)
        if(x>=ShootGame.WIDTH-this.width){ //x>=(屏幕宽-蜜蜂宽)时，x减(向左)
            xSpeed = -1;
        }
        if(x<=0){ //x<=0时，x加(向右)
            xSpeed = 1;
        }
    }

    /** 重写outOfBounds() */
    public boolean outOfBounds(){
        return this.y>=ShootGame.HEIGHT; //蜜蜂的y>=屏幕的高，即为越界
    }
}
